package de.akad.imp03.client.ui;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;

import de.akad.imp03.client.data.Rundendaten;


public class ItemCommand implements ClickHandler {

	private ControlCenter root;
	private Rundendaten rd;
	private String text;
	private String imageUrl;
	private int selectedItem;
	
	public ItemCommand(ControlCenter cc, Rundendaten rd, int item) {
		root = cc;
		this.rd = rd;
		selectedItem = item;
		this.text = rd.getItemText(item);
		this.imageUrl = rd.getImageUrl(item);
		
	}
	
	public void execute() {
		if (rd.isBudgetAusreichend(selectedItem)) {
			root.header.subtitle.setText(text);
			ImageContent content = new ImageContent(imageUrl);
			root.content.setPanel(content.onInitialize());
			root.footer.okCommand.setSelectedItem(selectedItem);
		}
	}

	@Override
	public void onClick(ClickEvent event) {
		this.execute();
		
	}
}
